from django.db import models
from django.contrib.auth.models import AbstractUser


class Readers(AbstractUser):
    """
 Custom user model for readers with additional attributes for student number,
 contact information, and name.
 """
    student_number = models.CharField(max_length=50, blank=True, null=True,
                                      help_text="The student's number.")
    contact_info = models.CharField(max_length=100, blank=True, null=True,
                                    help_text="Contact information for the reader.")
    name = models.CharField(max_length=100, blank=True, null=True,
                            help_text="Full name of the reader.")

    # Use related_name to avoid reverse accessor clashes
    groups = models.ManyToManyField(
        'auth.Group',
        related_name='readers_groups',  # Unique related_name
        blank=True,
        help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.'
    )

    user_permissions = models.ManyToManyField(
        'auth.Permission',
        related_name='readers_user_permissions',  # Unique related_name
        blank=True,
        help_text='Specific permissions for this user.'
    )

    def __str__(self):
        return self.username or self.name or "Unnamed Reader"

    class Meta:
        verbose_name = 'Reader'
        verbose_name_plural = 'Readers'
        ordering = ['username']  # Default ordering by username
